﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Windows;
using System.Threading;

namespace RecommendatioNetwork
{
    public class Listener : IContract
    {

        #region Metodi che implementano l'interfaccia IContract
        
        public void Search(Search search)
        {
            Console.WriteLine("Richiesta di ricerca da " + search.Uri.ToString());
            OnListnerSearch(search);
        }
        
        public void AddResponseSearch(Comment comment, Uri uri, Search search)
        {
            Console.WriteLine("Mi è arrivata una risposta da " + uri.ToString());
            OnAddResponse(new Packet() { Comment = comment, UriToSend = uri, Search = search });
        }
        
        #endregion

        #region Eventi da mandare al repository

        //public delegate void EventDelegate(object sender, System.EventArgs e);
        public static event EventHandler listnerSearch;
        public static event EventHandler addResponse;
       
        public virtual void OnListnerSearch(Search search)
        {
            if (listnerSearch != null)
            {
                listnerSearch(this,search); 		
            }
        }
        
        public virtual void OnAddResponse(Packet packet)
        {
            if (addResponse != null)
            {
                addResponse(this,packet); 	
            }
        }
        #endregion
    }
}